<template>
  <div style="height: 100%">
    <callSummary
      inputType="INSERT"
      :componentHeight="213"
      :propData.sync="callData"
      :randomNum.sync="callData.randomNum"
      :moduleType="moduleType"
      :showListen="showListen"
      :showDowload="showDowload"
      @changeCustomerRelation="changeCustomerRelation"
      ref="callTaskRef"
    ></callSummary>
  </div>
</template>

<script lang="ts">
import CallSummary from '@/components/commonSummary/index.vue'
import { Component, Vue, Prop } from 'vue-property-decorator'
import { CallCardModule } from '@/store/modules/cti/callCard'
@Component({ name: 'CallSummaryByCallData', components: { CallSummary } })
export default class CallSummaryByCallData extends Vue {
  @Prop({ default: 'dataCenter' }) private moduleType!: string
  @Prop({ default: false }) private showDowload!: boolean
  @Prop({ default: false }) private showListen!: boolean
  private callData: any = {}

  private updateSummaryData (callObj: any) {
    /*
    * importType: 调用的模块|类型 required
    * timeStamp: 时间戳 required
    * phone: 通话号码 required
    * custId: 客户Id required
    * custName: 客户名称 required
    * customerList: 该号码对应的locateCust列表
    * callSheetId: 通话卡片id（通话记录的_id）
    * cdr: 该通话记录对应的数据
    * cdrName: 来电、外呼
    */
    CallCardModule.CdrLocateCust({ type: 1, phone: callObj.phone }).then((res) => {
      if (res && res.success && res.data) {
        let cdrName: string = ''
        if (callObj.cdr.callType === 'incoming') { // 呼入、来电
          cdrName = 'cdr_call'
        }
        if (callObj.cdr.callType === 'dialout') { // 外呼
          cdrName = 'cdr_outbound'
        }
        callObj.cdr.superUniqueId = callObj.cdr._id // 王涛更新通话卡片用
        let importType = 'DataCenterCall'
        if (this.moduleType === 'autoCallTask') {
          importType = 'AutoCallTask'
        }
        Vue.set(this, 'callData', {
          importType, // 数据中心 - 通话记录
          timeStamp: new Date().getTime(),
          phone: callObj.phone,
          custId: callObj.cdr.customerId,
          custName: callObj.cdr.customerName,
          customerList: res.data,
          callSheetId: callObj.callSheetId,
          cdr: callObj.cdr,
          cdrName,
          randomNum: Math.random()
        })
      }
    })
  }

  private changeCustomerRelation (info) {
    // console.log('callData info:\n', info)
    this.$emit('changeCustomerRelation', info)
    CallCardModule.updateCardInfo(info)
  }
}
</script>

<style lang="stylus" scoped>
</style>
